package hierarchy

import (
	"gitcode.com/G-YT/ANN/server/global"
	"gitcode.com/G-YT/ANN/server/model/common/response"
	"gitcode.com/G-YT/ANN/server/service"
	"gitcode.com/G-YT/ANN/server/utils"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
)

type FdArticleApi struct {
}

var fdArticleService = service.ServiceGroupApp.HierarchyServiceGroup.FdArticleService

// GetArticle 獲取文章
// @Tags FdArticleAudio
// @Summary 創建FdArticleAudio
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body hierarchy.FdArticleAudio true "創建FdArticleAudio"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"獲取成功"}"
// @Router /fdArticle/getArticle [get]
func (fdArticleApi *FdArticleApi) GetArticle(c *gin.Context) {
	level := c.Query("level")
	id := c.Query("id")
	userID := utils.GetUserID(c)
	if articleList, err := fdArticleService.GetArticle(level, id, userID); err != nil {
		global.GVA_LOG.Error("創建失敗!", zap.Error(err))
		response.FailWithMessage("創建失敗", c)
	} else {
		response.OkWithData(articleList, c)
	}
}

// GetHotArticle 搜索文章&獲取热门搜索文章列表
// @Tags FdArticleAudio
// @Summary 搜索文章&獲取热门搜索文章列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body hierarchy.FdArticleAudio true "創建FdArticleAudio"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"獲取成功"}"
// @Router /fdArticle/getHotArticle [get]
func (fdArticleApi *FdArticleApi) GetHotArticle(c *gin.Context) {
	title := c.Query("title")
	userID := utils.GetUserID(c)
	if articleList, err := fdArticleService.GetHotArticle(userID, title); err != nil {
		global.GVA_LOG.Error("創建失敗!", zap.Error(err))
		response.FailWithMessage("創建失敗", c)
	} else {
		response.OkWithData(articleList, c)
	}
}

// GetMyCollect 獲取我的收藏文章
// @Tags FdArticleAudio
// @Summary 搜索文章&獲取热门搜索文章列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body hierarchy.FdArticleAudio true "創建FdArticleAudio"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"獲取成功"}"
// @Router /fdArticle/getMyCollect [get]
func (fdArticleApi *FdArticleApi) GetMyCollect(c *gin.Context) {
	userID := utils.GetUserID(c)
	if articleList, err := fdArticleService.GetMyCollect(userID); err != nil {
		global.GVA_LOG.Error("創建失敗!", zap.Error(err))
		response.FailWithMessage("創建失敗", c)
	} else {
		response.OkWithData(articleList, c)
	}
}

// ForwardArticle 转发文章
// @Tags FdArticleAudio
// @Summary 转发文章
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body hierarchy.FdArticleAudio true "創建FdArticleAudio"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"獲取成功"}"
// @Router /fdArticle/forwardArticle [put]
func (fdArticleApi *FdArticleApi) ForwardArticle(c *gin.Context) {
	types := c.Query("types")
	id := c.Query("id")
	if err := fdArticleService.ForwardArticle(types, id); err != nil {
		global.GVA_LOG.Error("創建失敗!", zap.Error(err))
		response.FailWithMessage("转发失敗", c)
	} else {
		response.Result(200, "", "转发成功", c)
	}
}
